package com.bsoft.exchange.config.dozer;

import java.util.ArrayList;
import java.util.List;

import org.dozer.Mapper;
import org.springframework.stereotype.Component;


@Component
public class DozerUtils {
	
//	@Autowired
//	Mapper dozerMapper;
	
	public static  <T> T map(final Mapper dozerMapper, Object source, Class<T> destinationClass) {
        if(source == null) {
        	return null;
        }else {
        	return dozerMapper.map(source, destinationClass);
        }
    }

	 /**
     * 封装dozer处理集合的方法：List<S> --> List<T>
     */
 /*   public static <T, S> List<T> mapList(List<S> sourceList, Class<T> targetObjectClass) {
        List<T> targetList = new ArrayList<T>();
        for (S s : sourceList) {
            targetList.add(dozerMapper.map(s, targetObjectClass));
        }
        return targetList;
    }
	*/
    /**
     * 封装dozer处理集合的方法：List<S> --> List<T>
     */
    public static <T, S> List<T> mapList(final Mapper mapper, List<S> sourceList, Class<T> targetObjectClass) {
        List<T> targetList = new ArrayList<T>();
        for (S s : sourceList) {
            targetList.add(mapper.map(s, targetObjectClass));
        }
        return targetList;
    }
    
    
}